###########################################################################
#	$Id: index.html 7 2007-03-17 09:23:38Z beave $
###########################################################################

@main[]

^use[Archive.p]

$TMP_PATH[^file:dirname[^file:fullpath[dummy]]]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xml:lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=$response:charset" />
		<title>Parser 3. Archive. How To Use (sample file).</title>
		<link rel="stylesheet" type="text/css" href="common.css" /> 
		<script type="text/javascript" src="common.js"></script>
	</head>

	<body>

#		initializing class
		^Archive:init[
			$.SCRIPT_PATH[]
		]

		<h1>Archive. How To Use (sample file).</h1>

		^printSendResult[]

		<form action="$request:uri" method="post" enctype="multipart/form-data">

			<div>
				<input type="hidden" name="action" value="send" />
				<input id="FileCounter" type="hidden" name="files" value="1" />
			</div>

			<p>
				<label>Temp directory</label>
				<input type="text" value="$TMP_PATH" disabled="disabled" />
			</p>

			<p id="FilesContent">
				<label>Files</label>
				<a onclick="addField('FilesContent')^;" href="#">add field</a>
				<input type="file" name="file1" />
			</p>

			<p>
				<label>File name</label>
				<input type="text" name="filename" value="test" />
				<select name="file_ext">
					<option value="tar.gz">.tar.gz</option>
					<option value="tar.bz2">.tar.bz2</option>
					<option value="zip">.zip</option>
					<option value="rar">.rar</option>
				</select>
			</p>

			<p>
				<label>Delete files when archive created</label>
				<input type="checkbox" name="delete" value="1" />
			</p>

			<p class="submit">
				<input type="submit"/>
			</p>

		</form>

	</body>
</html>
#end @main[]



@printSendResult[][sArchive;tFiles;tContent]
^if($form:action eq 'send'){

	<div class="process">

		$sArchive[$TMP_PATH/${form:filename}.$form:file_ext]

		$tFiles[^table::create{path}]

#		saving files
		^for[i](1;$form:files){
			^if(def $form:[file$i]){
				^form:[file$i].save[binary;$TMP_PATH/$form:[file$i].name]
				<p>File <strong>$form:[file$i].name</strong> is successfully saved in <strong>$TMP_PATH</strong>.</p>
				^tFiles.append{$form:[file$i].name}
			}
		}

#		creating archive with uploaded wiles
		^Archive:create[$sArchive;$tFiles]

		^if(-f $sArchive){
			<p>Archive <strong>${form:filename}.$form:file_ext</strong> is successfully created in <strong>$TMP_PATH</strong>.</p>
		}

#		if checked 'delete files' option, deleting files
		^if(^form:delete.int(0)){
			^for[i](1;$form:files){
				^if(def $form:[file$i] && -f '$TMP_PATH/$form:[file$i].name'){
					^file:delete[$TMP_PATH/$form:[file$i].name]
					<p>File <strong>$form:[file$i].name</strong> is successfully deleted from <strong>$TMP_PATH</strong>.</p>
				}
			}
		}

		$tContent[^Archive:list[$sArchive]]

		<h4>Archive content.</h4>

		<table>
			<thead>
				<tr>
					<th>Path</th>
					<th>Size</th>
					<th>Date &amp^; Time</th>
				</tr>
			</thead>
			<tbody>
				^if($tContent){
					^tContent.menu{
						<tr>
							<td>$tContent.path</td>
							<td>$tContent.size</td>
							<td>$tContent.dt</td>
						</tr>
					}
				}
			</tbody>
		</table>

	</div>
	
}
#end @sendForm[]
